
const app = getApp();
Page({
  data: {
    anserN1:'',
    anserQ1:'',
    anserT1: '',
    anserN2: '',
    anserQ2: '',
    anserT2: '',
    anserN3: '',
    anserQ3: '',
    anserT3: '',
    anserN4: '',
    anserQ4: '',
    anserT4: '',
    anserN5: '',
    anserQ5: '',
    anserT5: '',
    anser1:[{
      anId:0,
      num:'A',
      value:'《保险代理经营许可证》',
      type:false
    },{
      anId:1,
      num:'B',
      value:'《保险代理执照》',
      type:false
    },{
        anId:2,
        num:'C',
        value:'《身份证》',
      type:false
    },{
        anId:3,
        num:'D',
        value:'《保险代理从业人员展业证书》或《保险代理从业人员执业证书》',
      type:true
    },],
    anser3: [{
      anId: 1,
      num: 'A',
      value: '要保人',
      type: false
    }, {
      anId: 2,
      num: 'B',
        value: '投保人或被保险人',
      type: true
    }, {
      anId: 3,
      num: 'C',
      value: '保险人',
      type: false
    }, {
      anId: 4,
      num: 'D',
        value: '受益人或被保险人',
      type: false
    },],
    anser2: [{
      anId: 1,
      num: 'A',
      value: '《保险法》',
      type: false
    }, {
      anId: 2,
      num: 'B',
      value: '《保险代理从业人员职业道德指引》',
      type: true
    }, {
      anId: 3,
      num: 'C',
      value: '《消费者权益保护法》',
      type: false
    }, {
      anId: 4,
      num: 'D',
      value: '《民法通则》',
      type: false
    },],
    anser4: [{
      anId: 1,
      num: 'A',
      value: '减少风险事故的发生机会',
      type: false
    }, {
      anId: 2,
      num: 'B',
        value: '减轻企业.家庭和个人对风险及潜在损失的烦恼和优惠',
        type: false
    }, {
      anId: 3,
      num: 'C',
        value: '分散风险.补偿损失',
      type: false
    }, {
      anId: 4,
      num: 'D',
        value: '最小成本获得最大安全保障',
      type: true
    },],
    anser5: [{
      anId: 1,
      num: 'A',
      value: '人寿保险',
      type: false
    }, {
      anId: 2,
      num: 'B',
        value: '人身意外伤害保险',
      type: true
    }, {
      anId: 3,
      num: 'C',
        value: '健康保险',
      type: false
    }, {
      anId: 4,
      num: 'D',
        value: '两全保险',
      type: false
    },],
    loading:false,

    id:'',
    tenancyName:'',
    password:'',
    name:'',
    phone:'',
    idnumber:''
     
  },
  onLoad: function (options) {
    console.log(options)
    var _this = this
    _this.setData({
      id:options.id,
      tenancyName: options.tenancyName,
      password:options.password,
      phone: options.phone,
      name: options.name,
      idnumber: options.idnumber,
    })
    console.log(_this.data.id)
   
  },
  onShow: function () {
    wx.showModal({
      title: '注册答题',
      content: '注册成为保险代理从业人员之前需答题考核（共5题）',
      showCancel:false,
      success: function (res) {
       
      }
    })
  },
  qus1:function(e){
    console.log(e)
    const _this = this;
    var data = e.currentTarget.dataset
    _this.setData({
      anserN1: data.index,
      anserQ1: data.num,
      anserT1: data.type
    })
  },
  qus2: function (e) {
    console.log(e)
    const _this = this;
    var data = e.currentTarget.dataset
    _this.setData({
      anserN2: data.index,
      anserQ2: data.num,
      anserT2: data.type
    })
  },
  qus3: function (e) {
    console.log(e)
    const _this = this;
    var data = e.currentTarget.dataset
    _this.setData({
      anserN3: data.index,
      anserQ3: data.num,
      anserT3: data.type
    })
  },
  qus4: function (e) {
    console.log(e)
    const _this = this;
    var data = e.currentTarget.dataset
    _this.setData({
      anserN4: data.index,
      anserQ4: data.num,
      anserT4: data.type
    })
  },
  qus5: function (e) {
    console.log(e)
    const _this = this;
    var data = e.currentTarget.dataset
    _this.setData({
      anserN5: data.index,
      anserQ5: data.num,
      anserT5: data.type
    })
  },
  toregister: function () {
    // wx.navigateTo({
    //   url: '../register/register',
    // })

    wx.navigateTo({
      url: '../veranswer/veranswer',
    })
  },
  tosubmit:function(){
    var _this = this
    console.log(_this.data.anserT1)
    
    // console.log(anserT1)
    var anserT1 = _this.data.anserT1,
      anserT2 = _this.data.anserT2,
      anserT3 = _this.data.anserT3,
      anserT4 = _this.data.anserT4,
      anserT5 = _this.data.anserT5;

    if (anserT1 == true && anserT2 == true && anserT3 == true && anserT4 == true && anserT5 == true){

      _this.setData({
        loading: true
      })
      wx.request({
        url: app.globalData.path + 'services/RegisterCirc',
        data: {
          id: _this.data.id,
        },
        method: 'POST',
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: function (res) {
          if (res.data.result.token) {
            _this.setData({
              loading: false
            })
            app.globalData.authorization = res.data.result.token;
            wx.reLaunch({
              url: '../addcard/addcard?phone=' + _this.data.phone + '&name=' + _this.data.name + '&idnumber=' + _this.data.idnumber + '&from=register',
            })
          } else {
            _this.setData({
              loading: false
            })
            if (res.data.error.code == 1) {
              wx.showToast({
                title: '手机号已被注册，请登录',
                icon: 'none',
                duration: 2000
              })
            } else if (res.data.error.code == 2) {
              wx.showToast({
                title: '身份证号已被注册，请登录',
                icon: 'none',
                duration: 2000
              })
            } else {
              wx.showToast({
                title: res.data.error.message,
                icon: 'none',
                duration: 2000
              })
            }
          }
        }
      })  

      // wx.navigateTo({
      //   url: '../addcard/addcard',
      // })
    }else{
      _this.setData({
        loading: false
      })
      wx.showModal({
        // title: '注册答题',
        content: '请输入所有题正确答案',
        showCancel: false,
        success: function (res) {

        }
      })
    }
  }
});